/***************************************************************************
 *   Copyright (C) 20018 - 2019 by chj <1019487871@qq.com>     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef __LOSBSP_LCD_H__
#define __LOSBSP_LCD_H__

#ifdef __cplusplus
extern "C" {
#endif

//LCDÖØÒª²ÎÊý¼¯
typedef struct
{
    uint16_t width;          //LCD ¿í¶È
    uint16_t height;         //LCD ¸ß¶È
    uint16_t id;             //LCD ID
    uint8_t  dir;            //ºáÆÁ»¹ÊÇÊúÆÁ¿ØÖÆ£º0£¬ÊúÆÁ£»1£¬ºáÆÁ¡£
    uint16_t wramcmd;        //¿ªÊ¼Ð´gramÖ¸Áî
    uint16_t  setxcmd;       //ÉèÖÃx×ø±êÖ¸Áî
    uint16_t  setycmd;       //ÉèÖÃy×ø±êÖ¸Áî
}_lcd_dev;

//LCD²ÎÊý
extern _lcd_dev lcddev; //¹ÜÀíLCDÖØÒª²ÎÊý
//LCDµÄ»­±ÊÑÕÉ«ºÍ±³¾°É«
extern uint16_t  POINT_COLOR;//Ä¬ÈÏºìÉ«
extern uint16_t  BACK_COLOR; //±³¾°ÑÕÉ«.Ä¬ÈÏÎª°×É«


//////////////////////////////////////////////////////////////////////////////////
//-----------------LCD¶Ë¿Ú¶¨Òå----------------
#define LCD_LED PBout(15)       //LCD±³¹â            PB15
//LCDµØÖ·½á¹¹Ìå
typedef struct
{
    uint16_t LCD_REG;
    uint16_t LCD_RAM;
} LCD_TypeDef;
//Ê¹ÓÃNOR/SRAMµÄ Bank1.sector4,µØÖ·Î»HADDR[27,26]=11 A6×÷ÎªÊý¾ÝÃüÁîÇø·ÖÏß
//×¢ÒâÉèÖÃÊ±STM32ÄÚ²¿»áÓÒÒÆÒ»Î»¶ÔÆä! 111 1110=0X7E
#define LCD_BASE        ((uint32_t)(0x6C000000 | 0x0000007E))
#define LCD             ((LCD_TypeDef *) LCD_BASE)
//////////////////////////////////////////////////////////////////////////////////

//É¨Ãè·½Ïò¶¨Òå
#define L2R_U2D  0 //´Ó×óµ½ÓÒ,´ÓÉÏµ½ÏÂ
#define L2R_D2U  1 //´Ó×óµ½ÓÒ,´ÓÏÂµ½ÉÏ
#define R2L_U2D  2 //´ÓÓÒµ½×ó,´ÓÉÏµ½ÏÂ
#define R2L_D2U  3 //´ÓÓÒµ½×ó,´ÓÏÂµ½ÉÏ

#define U2D_L2R  4 //´ÓÉÏµ½ÏÂ,´Ó×óµ½ÓÒ
#define U2D_R2L  5 //´ÓÉÏµ½ÏÂ,´ÓÓÒµ½×ó
#define D2U_L2R  6 //´ÓÏÂµ½ÉÏ,´Ó×óµ½ÓÒ
#define D2U_R2L  7 //´ÓÏÂµ½ÉÏ,´ÓÓÒµ½×ó

#define DFT_SCAN_DIR  L2R_U2D  //Ä¬ÈÏµÄÉ¨Ãè·½Ïò

//»­±ÊÑÕÉ«
#define WHITE            0xFFFF
#define BLACK            0x0000
#define BLUE             0x001F
#define BRED             0XF81F
#define GRED             0XFFE0
#define GBLUE            0X07FF
#define RED              0xF800
#define MAGENTA          0xF81F
#define GREEN            0x07E0
#define CYAN             0x7FFF
#define YELLOW           0xFFE0
#define BROWN            0XBC40 //×ØÉ«
#define BRRED            0XFC07 //×ØºìÉ«
#define GRAY             0X8430 //»ÒÉ«
//GUIÑÕÉ«

#define DARKBLUE         0X01CF //ÉîÀ¶É«
#define LIGHTBLUE        0X7D7C //Ç³À¶É«
#define GRAYBLUE         0X5458 //»ÒÀ¶É«
//ÒÔÉÏÈýÉ«ÎªPANELµÄÑÕÉ«

#define LIGHTGREEN       0X841F //Ç³ÂÌÉ«
//#define LIGHTGRAY        0XEF5B //Ç³»ÒÉ«(PANNEL)
#define LGRAY            0XC618 //Ç³»ÒÉ«(PANNEL),´°Ìå±³¾°É«

#define LGRAYBLUE        0XA651 //Ç³»ÒÀ¶É«(ÖÐ¼ä²ãÑÕÉ«)
#define LBBLUE           0X2B12 //Ç³×ØÀ¶É«(Ñ¡ÔñÌõÄ¿µÄ·´É«)

void LCD_Init(void);                                                        //³õÊ¼»¯
void LCD_DisplayOn(void);                                                   //¿ªÏÔÊ¾
void LCD_DisplayOff(void);                                                  //¹ØÏÔÊ¾
void LCD_Clear(uint16_t Color);                                                  //ÇåÆÁ
void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);                                     //ÉèÖÃ¹â±ê
void LCD_DrawPoint(uint16_t x,uint16_t y);                                            //»­µã
void LCD_Fast_DrawPoint(uint16_t x,uint16_t y,uint16_t color);                             //¿ìËÙ»­µã
uint16_t  LCD_ReadPoint(uint16_t x,uint16_t y);                                            //¶Áµã
void LCD_Draw_Circle(uint16_t x0,uint16_t y0,uint8_t r);                                   //»­Ô²
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);                          //»­Ïß
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);                     //»­¾ØÐÎ
void LCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color);                       //Ìî³äµ¥É«
void LCD_Color_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t *color);                //Ìî³äÖ¸¶¨ÑÕÉ«
void LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint8_t size,uint8_t mode);                      //ÏÔÊ¾Ò»¸ö×Ö·û
void LCD_ShowNum(uint16_t x,uint16_t y,uint32_t num,uint8_t len,uint8_t size);                       //ÏÔÊ¾Ò»¸öÊý×Ö
void LCD_ShowxNum(uint16_t x,uint16_t y,uint32_t num,uint8_t len,uint8_t size,uint8_t mode);              //ÏÔÊ¾ Êý×Ö
void LCD_ShowString(uint16_t x,uint16_t y,uint16_t width,uint16_t height,uint8_t size,uint8_t *p);        //ÏÔÊ¾Ò»¸ö×Ö·û´®,12/16×ÖÌå

void LCD_WriteReg(uint16_t LCD_Reg, uint16_t LCD_RegValue);
uint16_t LCD_ReadReg(uint16_t LCD_Reg);
void LCD_WriteRAM_Prepare(void);
void LCD_WriteRAM(uint16_t RGB_Code);
void LCD_SSD_BackLightSet(uint8_t pwm);                          //SSD1963 ±³¹â¿ØÖÆ
void LCD_Scan_Dir(uint8_t dir);                                  //ÉèÖÃÆÁÉ¨Ãè·½Ïò
void LCD_Display_Dir(uint8_t dir);                               //ÉèÖÃÆÁÄ»ÏÔÊ¾·½Ïò
void LCD_Set_Window(uint16_t sx,uint16_t sy,uint16_t width,uint16_t height);    //ÉèÖÃ´°¿Ú
//LCD·Ö±æÂÊÉèÖÃ
#define SSD_HOR_RESOLUTION      800     //LCDË®Æ½·Ö±æÂÊ
#define SSD_VER_RESOLUTION      480     //LCD´¹Ö±·Ö±æÂÊ
//LCDÇý¶¯²ÎÊýÉèÖÃ
#define SSD_HOR_PULSE_WIDTH     1       //Ë®Æ½Âö¿í
#define SSD_HOR_BACK_PORCH      46      //Ë®Æ½Ç°ÀÈ
#define SSD_HOR_FRONT_PORCH     210     //Ë®Æ½ºóÀÈ

#define SSD_VER_PULSE_WIDTH     1       //´¹Ö±Âö¿í
#define SSD_VER_BACK_PORCH      23      //´¹Ö±Ç°ÀÈ
#define SSD_VER_FRONT_PORCH     22      //´¹Ö±Ç°ÀÈ
//ÈçÏÂ¼¸¸ö²ÎÊý£¬×Ô¶¯¼ÆËã
#define SSD_HT  (SSD_HOR_RESOLUTION+SSD_HOR_BACK_PORCH+SSD_HOR_FRONT_PORCH)
#define SSD_HPS (SSD_HOR_BACK_PORCH)
#define SSD_VT  (SSD_VER_RESOLUTION+SSD_VER_BACK_PORCH+SSD_VER_FRONT_PORCH)
#define SSD_VPS (SSD_VER_BACK_PORCH)

#ifdef __cplusplus
}
#endif

#endif
